package 
{
	import feathers.FeathersBase;
	import feathers.themes.AeonDesktopTheme;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import robotlegs.Config;
	import controller.GlobalStaticController;
	import core.controller.NavigationController;
	import core.mediator.NavigationMediator;
	import core.model.NavigationModel;
	import core.servise.ViewFactory;
	import core.view.INavigationView;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import model.Model;
	import robotlegs.bender.bundles.mvcs.MVCSBundle;
	import robotlegs.bender.extensions.contextView.ContextView;
	import robotlegs.bender.framework.impl.Context;
	import robotlegs.extensions.starlingViewMap.StarlingViewMapExtension;
	import robotlegs.StarlingConfig;
	import starling.core.Starling;
	import starling.events.Event;
	import view.RootViewMediator;
	import starling.display.Sprite;
	/**
	 * ...
	 * @author 
	 */
	public class Main extends flash.display.Sprite
	{
		/*
		private var _lines:Vector.<Line> = new Vector.<Line>();
		private var _curLine:Line;
		private var _convergentPoint:PointView=new PointView();
		*/
		
		//private var _nCont:NavigationController = new NavigationController();
		//private var _nModel:NavigationModel = new NavigationModel();
		//private var _rootView:INavigationView;
		//
		//private var _rvMed:NavigationMediator;
		
		
		
		
		
		//private var _context:Context;
		//private var _fearhersBase:FeathersBase;
		
		public function Main():void 
		{				
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			this.mouseEnabled = this.mouseChildren = false;
			
			const fearhersBase:FeathersBase = new FeathersBase(stage, starling.display.Sprite);
			
			const context:Context = new Context();
			context.install(MVCSBundle,StarlingViewMapExtension);
			context.configure(
					StarlingConfig,
					Config,
					new ContextView(this),fearhersBase.starling);
			context.initialize();
			
			//addChild(ViewFactory.create('RootView') as Sprite);
		}
		/*
		private function onUP(e:MouseEvent):void 
		{
			stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMM);
			
			createConvergentPoint();
		}
		
		private function onMD(e:MouseEvent):void 
		{
			_curLine = new Line();
			addChild(_curLine);
			_curLine.p1.x = mouseX;
			_curLine.p1.y = mouseY;
			
			stage.addEventListener(MouseEvent.MOUSE_MOVE, onMM);
			onMM();
		}
		
		private function onMM(e:MouseEvent=null):void 
		{
			_curLine.p2.x = mouseX;
			_curLine.p2.y = mouseY;
			_curLine.drow();
		}
		
		private function createConvergentPoint():void 
		{
			_lines.push(_curLine);
			if (_lines.length >0) {
			
				_convergentPoint.x = 0;
				_convergentPoint.y = 0;
				
				var count:uint = 0;
				for (var i:int = _lines.length-1; i > 0; i--) 
				{
					for (var j:int = 0; j < i; j++) 
					{
						var p:Point=MathLib.intersection2(_lines[i], _lines[j]);
						_convergentPoint.x += p.x;
						_convergentPoint.y += p.y;
						count++;
					}
				}
				
				_convergentPoint.x /= count ;
				_convergentPoint.y /= count ;
			}
			
			graphics.clear();
			graphics.lineStyle(0, 0);
			
			
			var lL:Line = new Line();
			lL.p2.y = 1;
			
			var lR:Line = new Line();
			lR.p1.x = 800;
			lR.p2.x = 800;
			lR.p2.y = 1;
			
			var lT:Line = new Line();
			lT.p2.x = 1;
			
			var lD:Line = new Line();
			lD.p1.y = 600;
			lD.p2.x = 1;
			lD.p2.y = 600;
			
			var l:Line = new Line();
			l.p1 = _convergentPoint;
			for each(var line:Line in _lines) 
			{
				var p:Point = Point.interpolate(new Point(line.p1.x, line.p1.y), new Point(line.p2.x, line.p2.y),.5);
				//graphics.moveTo(_convergentPoint.x, _convergentPoint.y);
				//graphics.lineTo(p.x, p.y);
				
				l.p2.x = p.x;
				l.p2.y = p.y;
				
				var lp:Point = MathLib.intersection2(l, lL);
				var rp:Point = MathLib.intersection2(l, lR);
				var tp:Point = MathLib.intersection2(l, lT);
				var dp:Point = MathLib.intersection2(l, lD);
				
				var ar:Array = [];
				if (lp.y >= 0 && lp.y <= 600) ar.push(lp);
				if (rp.y >= 0 && rp.y <= 600) ar.push(rp);
				if (tp.x >= 0 && tp.x <= 800) ar.push(tp);
				if (dp.x >= 0 && dp.x <= 800) ar.push(dp);
				
				//trace(ar.length)
				//x red
				//y grren
				//z blue
				graphics.moveTo(ar[0].x, ar[0].y);
				graphics.lineTo(ar[1].x, ar[1].y);
			}
			
		}
		
		*/
	}
	
}